package com.pachong.frameworkdemo.module1;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;

import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.frameworkbase.dialog.IOSAlertListFragment;
import com.pachong.android.framework.picture.picker.release.SelectAlbumActivity;
import com.pachong.android.framework.picture.picker.utils.TakePhoto;
import com.pachong.frameworkdemo.R;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PicturePickerDemoActivity extends BaseActivity {

    private static final int TAKE_PHOTO_IMAGE = 201;
    private static final int PICK_UP_IMAGE = 202;
    private static final int MAXNUM_SELECTPIC = 8;
    private static final int TAKE_PHOTO = 0;
    private static final int PICK_PHOTO = 1;
    @Bind(R.id.btn_main_start)
    Button btnMainStart;

    private Context mContext = this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_picture_picker_demo, null);
        return view;
    }

    @OnClick(R.id.btn_main_start)
    public void onClick() {
        final String[] actionArr = new String[]{"拍照", "从相册中选择"};
        final IOSAlertListFragment diaFrag = new IOSAlertListFragment();
        diaFrag.setActionList(new AdapterView.OnItemClickListener() {
                                  @Override
                                  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                      switch (position) {
                                          case TAKE_PHOTO:
                                              Intent intent_TakePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                              Uri imageUri = TakePhoto.getInstance().getOutputMediaFileUri(mContext);
                                              intent_TakePhoto.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                                              startActivityForResult(intent_TakePhoto, TAKE_PHOTO_IMAGE);
                                              break;
                                          case PICK_PHOTO:
                                              Intent intent_PickPhoto = new Intent(PicturePickerDemoActivity.this, SelectAlbumActivity.class);
                                              intent_PickPhoto.putExtra(SelectAlbumActivity.RELEASE_IMGS_NUM, 0);
                                              intent_PickPhoto.putExtra(SelectAlbumActivity.INTENT_MAX_NUM, MAXNUM_SELECTPIC);
                                              startActivityForResult(intent_PickPhoto, PICK_UP_IMAGE);
                                              break;
                                      }
                                      diaFrag.dismiss();
                                  }
                              },
                actionArr).show(getSupportFragmentManager());

         /*SelectPicDialogFragment dialog = new SelectPicDialogFragment();
        dialog.setOnClickListener(new SelectPicDialogFragment.OnClickListener() {
            @Override
            public void takePhoto() {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                Uri imageUri = TakePhoto.getInstance().getOutputMediaFileUri(mContext);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                startActivityForResult(intent, TAKE_PHOTO_IMAGE);
            }

            @Override
            public void pickPhoto() {
                Intent intent = new Intent(PicturePickerDemoActivity.this, SelectAlbumActivity.class);
                intent.putExtra(SelectAlbumActivity.RELEASE_IMGS_NUM, 0);
                intent.putExtra(SelectAlbumActivity.INTENT_MAX_NUM, MAXNUM_SELECTPIC);
                startActivityForResult(intent, PICK_UP_IMAGE);
            }
        });
        dialog.show(getSupportFragmentManager(), "photo_dialog");*/
    }
}